<?php

class viewtest {


	public $tVar = null;
	public $path = null;

	function __construct($path){
	
		$this->path = $path;
	
	}
	
	public function setpath($path) {
	
		$this->path = $path;
	
	}


    public function assign($name,$value=''){
        if(is_array($name)) {
            $this->tVar   =  array_merge($this->tVar,$name);
        }elseif(is_object($name)){
            foreach($name as $key =>$val)
                $this->tVar[$key] = $val;
        }else {
            $this->tVar[$name] = $value;
        }
    }
	
	public function display($tpl) {
		
		if(!empty($this->tVar))
			extract($this->tVar, EXTR_OVERWRITE);
		$path = $this->path;
		$file = $path.$tpl;
		
		include $file;
	
	}
	
	public function render($tpl) {
	
		if(!empty($this->tVar))
			extract($this->tVar, EXTR_OVERWRITE);
		$path = $this->path;
		$file = $path.$tpl;
		
        //页面缓存
        ob_start();
        ob_implicit_flush(0);
		
		include $file;
		
		//清空缓存
		$content = ob_get_clean();
		
		return $content;
		
	
	
	}




}